﻿// LTDMC_IO_Dlg.cpp: 实现文件
//

#include "pch.h"
#include "SakerProject.h"
#include "LTDMC_IO_Dlg.h"
#include "afxdialogex.h"

#include "xxUIdesign.h"
#include "Project.h"


// CLTDMC_IO_Dlg 对话框
CLTDMC_IO_Dlg * m_LTDMC_IO;

IMPLEMENT_DYNAMIC(CLTDMC_IO_Dlg, CDialogEx)

CLTDMC_IO_Dlg::CLTDMC_IO_Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_LTDMC_IO, pParent)
{

}

CLTDMC_IO_Dlg::~CLTDMC_IO_Dlg()
{
}

void CLTDMC_IO_Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CLTDMC_IO_Dlg, CDialogEx)
	ON_WM_TIMER()
	ON_CONTROL_RANGE(BN_CLICKED, IDC_BUTTON_Y00, IDC_BUTTON_Y31, &CLTDMC_IO_Dlg::OnBnClickedOption)
END_MESSAGE_MAP()


// CLTDMC_IO_Dlg 消息处理程序


BOOL CLTDMC_IO_Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	InitIONames();
	

	if (Project.Icon_On == NULL) {
		Project.Icon_On = xx::GetButtonIco(this, IDC_BUTTON_S00, IDI_ICON_On);
		Project.Icon_Off = xx::GetButtonIco(this, IDC_BUTTON_S00, IDI_ICON_Off);
	}


	SetTimer(Project.nTimer_LTDMC_IO, 100, NULL);

	return TRUE;
}


void CLTDMC_IO_Dlg::OnCancel()
{
	KillTimer(Project.nTimer_LTDMC_IO);

	CDialogEx::OnCancel();
}


void CLTDMC_IO_Dlg::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == Project.nTimer_LTDMC_IO) {
		ShowIOstatus();
	}

	CDialogEx::OnTimer(nIDEvent);
}


void CLTDMC_IO_Dlg::ShowIOstatus() {
	int i = 0;
	for (int ID = IDC_BUTTON_S00; ID <= IDC_BUTTON_S31; ID++) {
		xx::CButtonIco(this, ID, (mmLTDMC.InBits[CurCardNo][i].CheckTrig() == TRUE) ? Project.Icon_On : Project.Icon_Off);
		i++;
	}
	i = 0;
	for (int ID = IDC_BUTTON_Y00; ID <= IDC_BUTTON_Y31; ID++) {
		xx::CButtonIco(this, ID, (mmLTDMC.OutBits[CurCardNo][i].CheckTrig() == TRUE) ? Project.Icon_On : Project.Icon_Off);
		i++;
	}

}

void CLTDMC_IO_Dlg::OnBnClickedOption(UINT nID) {
	int iOutBit = nID - IDC_BUTTON_Y00;
	mmLTDMC.OutBits[CurCardNo][iOutBit].SetReverse();
}

void CLTDMC_IO_Dlg::InitIONames() {
	int i = 0;
	for (int ID = IDC_STATIC_S00; ID <= IDC_STATIC_S31; ID++) {
		SetDlgItemText(ID, mmLTDMC.InBits[CurCardNo][i].NodeName);
		i++;
	}
	i = 0;
	for (int ID = IDC_STATIC_Y00; ID <= IDC_STATIC_Y31; ID++) {
		SetDlgItemText(ID, mmLTDMC.OutBits[CurCardNo][i].NodeName);
		i++;
	}
}